/*
 * MotorsPanel.java
 *
 * Created on 7. september 2007, 13:08
 */
package robotour.hardware.oldmotors;

/**
 *
 * @author  PC
 */
public class MotorsPanel extends javax.swing.JPanel {

    private Motors motors;

    /** Creates new form MotorsPanel
     * @param motors
     */
    public MotorsPanel(Motors motors) {
        this.motors = motors;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        leftPB = new javax.swing.JProgressBar();
        rightPB = new javax.swing.JProgressBar();
        leftByte = new javax.swing.JLabel();
        rightByte = new javax.swing.JLabel();

        leftPB.setValue(50);

        leftByte.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        leftByte.setText("00000000");

        rightByte.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        rightByte.setText("00000000");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(leftByte, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                    .addComponent(leftPB, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(rightByte, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(rightPB, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rightByte)
                    .addComponent(leftByte))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rightPB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(leftPB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(16, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public void repaint() {
        try {
            if (motors != null) {
                leftPB.setValue((int) (100 * motors.getSpeedLeft() / 2.5));
                rightPB.setValue((int) (100 * motors.getSpeedRight() / 2.5));
//                leftByte.setText(Integer.toBinaryString(Motors.getByte(Device.motors.getSpeedLeft())));
//                rightByte.setText(Integer.toBinaryString(Motors.getByte(Device.motors.getSpeedRight())));
            }
        } catch (Exception ex) {
        }

        super.repaint();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel leftByte;
    private javax.swing.JProgressBar leftPB;
    private javax.swing.JLabel rightByte;
    private javax.swing.JProgressBar rightPB;
    // End of variables declaration//GEN-END:variables
}
